package com.shangqing.web.controller.system;

import com.shangqing.common.core.domain.AjaxResult;
import com.shangqing.system.entity.*;
import com.shangqing.system.service.ISysFloodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(value = "pet", description = "洪涝信息控制器")
@RestController
public class SysFllodController {
	@Autowired
	private ISysFloodService floodService;

	@ApiOperation(value = "获取洪涝参数")
	@ResponseBody
	@GetMapping("/flood")
	public AjaxResult showfloodinfo() {
		List<Flood> floods = floodService.selectfloodinfo();
		if (floods.isEmpty()) {
			return AjaxResult.error("没有找到");
		} else {
			return AjaxResult.success("找到了", floods);
		}
	}

	@ApiOperation(value = "预警信息")
	@ResponseBody
	@GetMapping("/floodwarning")
	public AjaxResult showwarninginfo() {
		List<Floodwarning> floodwarnings = floodService.selectwarning();
		if (floodwarnings.isEmpty()) {
			return AjaxResult.error("没有找到");
		} else {
			return AjaxResult.success("找到了", floodwarnings);
		}
	}

	@ApiOperation(value = "按年统计每个城市不同洪涝级别的次数")
	@ResponseBody
	@PostMapping("/countfloodtype")
	public AjaxResult countgrade(@RequestParam("year") int year) {
		List<Floodall> floodalls = floodService.selectcounttype(year);
		if (floodalls.isEmpty()) {
			return AjaxResult.error("没有找到");
		} else {
			return AjaxResult.success("找到了", floodalls);
		}
	}

	@ApiOperation(value = "查询每个城市洪涝所占百分比")
	@ResponseBody
	@GetMapping("/selectfloodnum")
	public AjaxResult shownum() {
		List<FloodNumber> floodNumbers = floodService.selectfloodnum();
		if (floodNumbers.isEmpty()) {
			return AjaxResult.error("没有找到");
		} else {
			return AjaxResult.success("找到了", floodNumbers);
		}
	}

	@ApiOperation(value = "全区水位预警")
	@ResponseBody
	@GetMapping("/selectflood")
	public AjaxResult selectfloodgrade() {
		List<Map> maps = floodService.selecteveryflood();
		if (maps.isEmpty()) {
			return AjaxResult.error("没有找到");
		} else {
			return AjaxResult.success("找到了", maps);
		}
	}

	@ApiOperation(value = "全区灾情统计（近五个月）")
	@ResponseBody
	@GetMapping("/selectfivemonth")
	public AjaxResult selectfivemonth() {
		List<Map> maps = floodService.selectfivemonth();
		if (maps.isEmpty()) {
			return AjaxResult.error("没有找到");
		} else {
			return AjaxResult.success("找到了", maps);
		}
	}
}
